$(function () {
    $(function () {
        var options = {
            modalName: "新闻",
            url: "/render/newsManager/list",
            getInfoUrl: "/render/newsManager/get/{id}",
            updateUrl: "/render/newsManager/edit",
            removeUrl: "/render/newsManager/remove",
            createUrl: "/render/newsManager/add",
            searchUrl: "/render/newsManager/search",
            pageNumber:1,
            pageSize:7,
            columns: [
                {
                    checkbox: true,
                    formatter:checkboxMatter
                }, {
                    field: 'id',
                    title: 'ID',
                    align: "center",
                    width: '50px',
                    class:"colStyle",
                    sortable : true,
                    formatter:paramsMatter
                }, {
                    field: 'title',
                    title: '标题',
                    align: "center",
                    width: '100px',
                    class:"colStyle",
                    cellStyle:formatTableUnit,
                    formatter:paramsMatter
                }, {
                    field: 'cover_image',
                    title: '封面',
                    align: "center",
                    width: '88px',
                    class:"colStyle",
                    // formatter:paramsMatter
                    formatter:function paramsMatter(value) {
                        if (value != null) {
                            var span=document.createElement('span');
                            span.setAttribute('title',value);
                            var html="<img src='"+value+"' class='img-responsive img-rounded auto-shake'>";
                            span.innerHTML = html;
                            return span.outerHTML;
                        }
                    }
                }, {
                    field: 'top',
                    title: '是否置顶',
                    align: "center",
                    width: '88px',
                    class:"colStyle",
                    // formatter:paramsMatter
                    formatter: function (value) {
                        value = (value==1) ? 'yes' : 'no';
                        var span=document.createElement('span');
                        // span.setAttribute('title',value);
                        span.innerHTML = value;
                        return span.outerHTML;
                    }
                }, {
                    field: 'status',
                    title: '状态',
                    align: "center",
                    width: '70px',
                    sortable : true,
                    cellStyle:formatTableUnit,
                    // formatter:paramsMatter
                    formatter: function (value) {
                        value = (value==1) ? '上架' : '下架';
                        var span=document.createElement('span');
                        span.setAttribute('title',value);
                        span.innerHTML = value;
                        return span.outerHTML;
                    }
                }, {
                    field: 'comment',
                    title: '是否评论',
                    align: "center",
                    width: '88px',
                    class:"colStyle",
                    // formatter:paramsMatter
                    formatter: function (value) {
                        value = (value==1) ? 'yes' : 'no';
                        var span=document.createElement('span');
                        // span.setAttribute('title',value);
                        span.innerHTML = value;
                        return span.outerHTML;
                    }
                }, {
                    field: 'description',
                    title: '描述',
                    align: "center",
                    width: '150px',
                    class:"colStyle",
                    cellStyle:formatTableUnit,
                    formatter:paramsMatter
                }, {
                    field: 'create_time',
                    title: '创建时间',
                    width: '88px',
                    align: "center",
                    sortable : true,
                    cellStyle:formatTableUnit,
                    formatter:paramsMatter
                }/*, {
                    field: 'create_time',
                    title: '更新时间',
                    width: '88px',
                    align: "center",
                    sortable : true,
                    cellStyle:formatTableUnit,
                    formatter:paramsMatter
                }*/, {
                    field: 'operate',
                    title: '操作',
                    align: "center",
                    width: '100px',
                    formatter: operateFormatter //自定义方法，添加操作按钮
                }
            ]
        };
        // 初始化table组件
        var table = new Table(options);
        table.init();

        //search按钮绑定查询事件
        $('#btnSearch').on('click', function () {
            var searchtext = {
                id: $("#search-id").val(),
                title: $("#search-title").val(),
                type_id: $("#search-type_id").val()
            };
            // console.log(""+$("#search-username").val());
            if($("#search-id").val() === ""&&$("#search-title").val() === ""&&$("#search-type_id").val() === ""){
                postParams(options.url,options.onExpandRow,options,options.rowStyle,options.columns,null,true);
            }else {
                postParams(options.searchUrl,options.onExpandRow,options,options.rowStyle,options.columns,JSON.stringify(searchtext),false);
            }
        });
    });

    $(".close,.btn-default").on("click",function () {
        $(".modal").css("display","");
        $(".modal").removeClass("in");
        $(".modal-backdrop").removeClass("in");

        /*-----------------------*/
        $("#addOrUpdateForm_before").css("display","");
        $("#addOrUpdateForm_after").css("display","none");
        $(".addOrUpdateBtn_before").css("display","none");
        $(".addOrUpdateBtn_next").css("display","");
        // $(".addOrUpdateBtn").css("display","none");
        $(".addOrUpdateBtn_close").css("display","");
    });
});


// , {
//     field: 'type_id',
//         title: '类型',
//         align: "center",
//         width: '88px',
//         class:"colStyle",
//         formatter:paramsMatter
// }